/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Carito
 */
@Entity
@Table(name = "TRM")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Trm.findAll", query = "SELECT t FROM Trm t"),
    @NamedQuery(name = "Trm.findByIdtrm", query = "SELECT t FROM Trm t WHERE t.trmPK.idtrm = :idtrm"),
    @NamedQuery(name = "Trm.findByFecha", query = "SELECT t FROM Trm t WHERE t.fecha = :fecha"),
    @NamedQuery(name = "Trm.findByValor", query = "SELECT t FROM Trm t WHERE t.valor = :valor"),
    @NamedQuery(name = "Trm.findByIddato", query = "SELECT t FROM Trm t WHERE t.trmPK.iddato = :iddato")})
public class Trm implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TrmPK trmPK;
    @Size(max = 180)
    @Column(name = "FECHA")
    @Temporal(TemporalType.DATE)
    private Date fecha;
    @Column(name = "VALOR")
    private BigInteger valor;
    @JoinColumn(name = "IDDATO", referencedColumnName = "IDDATO", insertable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Dato dato;

    public Trm() {
    }

    public Trm(TrmPK trmPK) {
        this.trmPK = trmPK;
    }

    public Trm(BigInteger idtrm, BigInteger iddato) {
        this.trmPK = new TrmPK(idtrm, iddato);
    }

    @XmlElement
    public TrmPK getTrmPK() {
        return trmPK;
    }

    public void setTrmPK(TrmPK trmPK) {
        this.trmPK = trmPK;
    }

    @XmlElement
    public Date getFecha() {
        return fecha;
    }

    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    @XmlElement
    public BigInteger getValor() {
        return valor;
    }

    public void setValor(BigInteger valor) {
        this.valor = valor;
    }

    @XmlElement
    public Dato getDato() {
        return dato;
    }

    public void setDato(Dato dato) {
        this.dato = dato;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (trmPK != null ? trmPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Trm)) {
            return false;
        }
        Trm other = (Trm) object;
        if ((this.trmPK == null && other.trmPK != null) || (this.trmPK != null && !this.trmPK.equals(other.trmPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Trm[ trmPK=" + trmPK + " ]";
    }
    
}
